from app import db

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    ip = db.Column(db.String(45), nullable=True)  # 保留IP字段作为备用
    device_uuid = db.Column(db.String(36), nullable=False)  # 设备UUID
    device_fingerprint = db.Column(db.String(100), nullable=False)  # 设备指纹(伪MAC地址)
    signature = db.Column(db.Text, nullable=True)  # 保留文本签名作为备用
    signature_image = db.Column(db.Text, nullable=True)  # 存储签名图片的base64数据
    created_at = db.Column(db.DateTime, nullable=False, default=db.func.now())  # 签字时间
    room_number = db.Column(db.String(20), nullable=True)  # 门牌号
    
    __table_args__ = (
        db.UniqueConstraint('device_uuid', name='uq_user_device_uuid'),
        db.Index('idx_user_device_fingerprint', 'device_fingerprint'),
    )

    def __repr__(self):
        return f'<User {self.id}, UUID: {self.device_uuid}, Fingerprint: {self.device_fingerprint}, Signature: {self.signature}, Room: {self.room_number}>'